package com.zq.im.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.zq.im.R;
import com.zq.im.activity.FriendDetailActivity;
import com.zq.im.bean.RequestedFriendListBean;

import java.util.List;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

/**
 * Created by 张强 869518570@qq.com on 2020/9/2
 */
public class FriendRequestedListAdapter extends RecyclerView.Adapter<FriendRequestedListAdapter.FriendRequestedViewHolder> {

    private Context mContext;
    private List<RequestedFriendListBean> mRequestedFriends;

    public FriendRequestedListAdapter(Context context, List<RequestedFriendListBean> requestedFriends) {
        mContext = context;
        mRequestedFriends = requestedFriends;
    }


    public void setRequestedFriends(List<RequestedFriendListBean> requestedFriends) {
        mRequestedFriends = requestedFriends;
    }

    @NonNull
    @Override
    public FriendRequestedViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.friend_requested_list_item, parent, false);
        return new FriendRequestedViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull FriendRequestedViewHolder holder, int position) {
        final RequestedFriendListBean bean = mRequestedFriends.get(position);
        Glide.with(mContext).load(bean.getSendFaceImage()).error(R.mipmap.icon).into(holder.icon);
        holder.name.setText(bean.getSendUsername());

        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //点击好友请求
                Intent intent = new Intent(mContext, FriendDetailActivity.class);
                intent.setAction("fromFriendRequestListActivity");

                intent.putExtra("bean", bean);
                mContext.startActivity(intent);
            }
        });

    }

    @Override
    public int getItemCount() {
        if (mRequestedFriends == null || mRequestedFriends.size() == 0) {
            return 0;
        }
        return mRequestedFriends.size();
    }

    static class FriendRequestedViewHolder extends RecyclerView.ViewHolder {

        ImageView icon;
        TextView name;
        TextView requestMessage;
        TextView status;

        public FriendRequestedViewHolder(@NonNull View itemView) {
            super(itemView);
            icon = itemView.findViewById(R.id.icon);
            name = itemView.findViewById(R.id.name);
            requestMessage = itemView.findViewById(R.id.request_message);
            status = itemView.findViewById(R.id.status);
        }
    }

}
